﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace ZhCun.Framework.Common.CommonFunction
{
    public class Utils
    {
        /// <summary>
        /// 获取主机名
        /// </summary>
        public string GetHostName()
        {
            return Dns.GetHostName();
        }
        /// <summary>
        /// 获取主机IP
        /// </summary>
        public string GetHostIP()
        {
            IPHostEntry ipe = Dns.GetHostEntry(Dns.GetHostName());
            IPAddress ipa = ipe.AddressList[0];
            return ipa.ToString();
        }

        /// <summary>
        /// 获得16为GUID
        /// </summary>
        /// <returns></returns>
        public string GetGUID16()
        {
            long i = 1;
            Guid guid = Guid.NewGuid();
            foreach (byte b in guid.ToByteArray())
            {
                i *= ((int)b + 1);
            }
            return string.Format("{0:x}", i - DateTime.Now.Ticks).ToUpper();
        }
    }
}
